package com.ruoyi.project.king.series.service;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.project.king.series.domain.Series;
import com.ruoyi.project.king.series.mapper.SeriesMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SeriesServiceImpl  implements SeriesService{




    @Autowired
    private SeriesMapper seriesMapper;


    @Override
    public List<Series> findMore(Series series) {
        return seriesMapper.selectMore(series);
    }


    @Override
    public Series findSeriesBySid(int sid) {
        return seriesMapper.selectSeriesBySid(sid);
    }

    @Override
    public int save(Series series) {
        return seriesMapper.insert(series);
    }



    @Override
    public int updateSeries(Series series) {
        return seriesMapper.uptdateSeries(series);
    }

    @Override
    public boolean deleteSeriesBySid(int sid) {
        return seriesMapper.deleteSeriesBySid(sid)>0?true:false;
    }

    /**
     * 检验系列名称是否唯一
     * @param series 系列信息
     * @return 结果
     */
    @Override
    public boolean checkSeriesNameUnique(Series series) {
        int  sid= StringUtils.isNull(series.getSid()) ? -1 : series.getSid();

        Series info=seriesMapper.checkSeriesNameUnique(series.getSname());
        if (StringUtils.isNotNull(info) && info.getSid() != sid){
            return true;
        }
        return false;
    }

}
